using System;
using System.Collections.ObjectModel;

namespace RideMe.AddIns.Console
{
    /// <summary>
    /// This represents an entry within the console, either command or response output
    /// </summary>
    public class ConsoleEntry
    {
        #region Enums

        /// <summary>
        /// This defines the type of console entry
        /// </summary>
        public enum ConsoleEntryType
        {
            COMMAND,
            RESPONSE,
            ERROR
        }

        #endregion

        #region Private Variables

        private string _text;
        private ConsoleEntryType _type;

        #endregion

        #region Properties

        /// <summary>
        /// This returns the text for the entry
        /// </summary>
        public string Text
        {
            get { return _text; }
        }

        /// <summary>
        /// This returns the type of entry this is
        /// </summary>
        public ConsoleEntryType Type
        {
            get { return _type; }
        }

        #endregion

        #region Constructor

        /// <summary>
        /// Constructor to create the entry
        /// </summary>
        /// <param name="text"></param>
        /// <param name="type"></param>
        public ConsoleEntry(string text, ConsoleEntryType type)
        {
            _text = text;
            _type = type;
        }

        #endregion

        #region Static Methods

        /// <summary>
        /// This filters the specified collection and returns only those entries with the specified type
        /// </summary>
        /// <param name="type"></param>
        /// <param name="entries"></param>
        /// <returns></returns>
        public static Collection<ConsoleEntry> Filter(ConsoleEntryType type, Collection<ConsoleEntry> entries)
        {
            Collection<ConsoleEntry> newEntries = new Collection<ConsoleEntry>();
            foreach (ConsoleEntry entry in entries)
            {
                if (entry.Type == type)
                    newEntries.Add(entry);
            }
            return newEntries;
        }

        #endregion
    }
}
